# -*- coding: utf-8 -*-
"""
Created on Thu Aug 10 11:55:23 2023

@author: skunk69
"""

import json

chinese_name = u'青少年上网成瘾自评量表'
english_name = 'Adolescent Internet Addiction Self-Rating Scale'
abbreviation = 'AIASS'
category = u'应激及相关行为量表'

outline = u"""刘炳伦、郝伟和杨德森将项目反应理论首次引入精神医学领域编制成网络成瘾诊断量表。项目反应理论模型具有样本自由性与结果准确性优点，避免了经典测验理论存在的样本依赖性与信度不精确等缺陷。"""

instruction = u"""此表是为了您的健康状况而设计，请您认真回答。下列每一道题有五个备选答案，请选出您的一项选择。"""

with open('AIASS.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for key,line in enumerate(lines):
    _,value = line.strip().split('）',maxsplit=1)
    items[key+1] = value.strip()

reverse_items = []
scales = [u'网络成瘾症状',u'网络成瘾诱因']
L1 = [1,2]+list(range(4,14))+[15] # 网络成瘾症状
L2 = [3,14,16,17] # 网络成瘾诱因
scales_items = [L1,L2]

# check scales_items
print(f'scale length={[len(l) for l in scales_items]}')

check = []
for l in scales_items:
    check = check+l
print(f'len(check)={len(check)}')

# complementary set
check_set = {i for i in sorted(check)}^{i for i in range(1,18)}
print(f'complementary set= {check_set}')

factors = []
factors_scales = []
rating = [u'没有',u'不一定',u'有一点',u'大部分',u'总是']
score_rules = list(range(1,6))

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""《青少年上网成瘾自评量表》属于一个自评量表。"""

reliability = u"""正式样本为部分大中专学校学生。采用双参数多级计分模型进行IRT分析，结果表明，各项指标均符合项目反应理论要求。"""
validity = u"""结构效度良好。在效标关联效度方面，根据DSM-IV物质依赖分类与诊断标准，并参考Goldberg标准作为效标，对上网学生进行临床诊断，同时进行量表自评。结果显示，《青少年上网成瘾自评量表》对网络成瘾具有良好的鉴别能力。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""17个条目总分大于45分即表明上网成瘾，分数的高低反映了成瘾的严重程度。"""

applications = u"""各项指标检验表明《青少年上网成瘾自评量表》是可用的评定工具，实际应用效果尚待后续研究检验。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)